package com.vint.mi;


/**
 * 1.done
 *  乱序数组交换成正序，最少次数
 */
public class Mi23 {
    public static String solution(String line){
        long m = Long.parseLong(line.trim());
        long sub = m - calNSum(m);
        return String.valueOf(kthOfSn(sub));
    }

	//<=m的最小sn之和
	public static long calNSum(long m){
		int i = 0;
		int sum = 0;
		for(i=1;i<=Long.MAX_VALUE;i++){
			sum += lenOfSn(i);
			if(sum>m){
				sum -= lenOfSn(i);
				i--;
				break;
			}
		}
		return sum;
	}

    //<=m的最小sn
    public static long calN(long m){
    	int i = 0;
    	int sum = 0;
    	for(i=1;i<=Long.MAX_VALUE;i++){
    	    sum += lenOfSn(i);
    	    if(sum>m){
    	    	i--;
    	    	break;
	        }
	    }
	    return i;
    }

    //sn的位数
    public static long lenOfSn(long n){
    	int length = String.valueOf(n).length();
    	int len = length;
    	int ret = 0;
    	while(len--!=0){
    	    ret += Math.pow(10,len-1)*9*len;
        }
        ret += (n+1-Math.pow(10,length-1))*length;
    	return ret;
    }
    //sn中的第k个
	public static long kthOfSn(long k){
    	long ret = k;
    	long sum = 0;
    	long i = 1;
    	for(i=1; i<Long.MAX_VALUE;i++){
    	    sum += i * 9 * Math.pow(10, i-1);
    	    if(sum >= k) break;
	    }
	    if(sum==k){
    		return 9;
	    }else{
			long sub = (k - sum)%i;
			long t = (k - sum) / i;
			long base = (long)Math.pow(10,i-1);
			base += t;
			if(sub==0){
				return base%(long)Math.pow(10,i-1);
			}else{
				return (base+1)%(long)Math.pow(10,i-1);

			}
	    }
	}

    public static void main(String[] args) {
        //System.out.println(solution("1"));
	    //System.out.println(solution("6"));
	    System.out.println(solution("7"));
    }
}
